/*
 * Project: daycare-ent
 * Package: com.made2ordersoftware.daycare.domain
 * File: PersonEntity
 * Created on: Sep 15, 2013
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.daycare.domain;

import com.made2ordersoftware.daycare.domain.enums.Status;
import com.made2ordersoftware.util.StringUtility;
import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Abstract base class for all persons in day care system.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Entity
@Table(name = "person")
@Inheritance
@DiscriminatorColumn(name = "role", discriminatorType = DiscriminatorType.STRING)
@NamedQuery(name = "Person.findIDs", query = "SELECT p.id FROM PersonEntity p")
@XmlRootElement
public class PersonEntity implements Serializable {

    private static final Logger LOG = LoggerFactory.getLogger(PersonEntity.class);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    private Long id;
    @Basic(optional = false)
    @Column(name = "first_name")
    private String firstName;
    @Basic(optional = false)
    @Column(name = "last_name")
    private String lastName;
    @Basic(optional = false)
    @Enumerated(EnumType.STRING)
    private Status status;

    /**
     * Creates an instance of <code>PersonEntity</code>.
     */
    public PersonEntity() {
    }

    /**
     * Creates an instance of <code>PersonEntity</code>.
     *
     * @param firstName First name of person
     * @param lastName  Last name of person
     */
    public PersonEntity(String firstName, String lastName) {
        this.status = Status.ACTIVE;
        this.firstName = firstName;
        this.lastName = lastName;
    }

    /**
     * Returns the id of the PersonEntity.
     *
     * @return ID of person
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the id of the PersonEntity.
     *
     * @param id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Returns the status of the PersonEntity.
     *
     * @return status of person
     */
    public Status getStatus() {
        return status;
    }

    /**
     * Sets the status of the PersonEntity.
     *
     * @param status
     */
    public void setStatus(Status status) {
        this.status = status;
    }

    /**
     * Returns the first name of the PersonEntity.
     *
     * @return first name of person
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the first name of the PersonEntity.
     *
     * @param firstName
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Returns the last name of the PersonEntity.
     *
     * @return last name of person
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the last name of the PersonEntity.
     *
     * @param lastName
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof PersonEntity)) {
            return false;
        }
        PersonEntity other = (PersonEntity) object;
        return Objects.equals(this.id, other.getId());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\nPersonEntity{ id=").append(
                StringUtility.ifNotNullToString(getId()));
        sb.append(",\n\tfirstName=").append(getFirstName());
        sb.append(",\n\tlastName=").append(getLastName());
        sb.append(",\n\tstatus=").append(getStatus());
        sb.append("}");
        return sb.toString();
    }

}
